import { useSearchParams } from 'react-router-dom'
import { useRequest } from 'ahooks'
import { getQuestionListService } from '@/services/question'


function useLoadQuestionListData() {

    const [searchParams] = useSearchParams()

    const { data, loading, error} = useRequest(
        async ()=>{
            const keyword=searchParams.get('keyword') || ''

            const data=await getQuestionListService({ keyword })
            return data
        },
        {
            refreshDeps: [searchParams],  // 依赖于搜索参数的变化
        }
    )
    return { data, loading, error }
}

export default useLoadQuestionListData